import React, { Component } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import { Card, Badge, Table, Divider } from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from './BasicProfile.less';

@connect(({ profile, loading }) => ({
  profile,
  loading: loading.effects['profile/fetchBasic'],
}))
export default class BasicProfile extends Component {

  getQueryString(name) { 
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
    var r = this.props.location.search.substr(1).match(reg); 
    if (r != null) return unescape(r[2]); return null; 
  }

  componentDidMount() {
    const { dispatch } = this.props;
    var work_id = this.getQueryString('work_id')
    dispatch({
      type: 'profile/fetchBasic',
      payload: {
        work_id:work_id,
      },
    });
  }
  

  render() {
    const { profile, loading } = this.props;
    const { workresults } = profile;
    const goodsColumns = [
      {
        title: '收录数量',
        dataIndex: 'count',
        key: 'count',
      },
      {
        title: 'Domain',
        dataIndex: 'domain',
        key: 'domain',
      },
      {
        title: 'Url数量',
        dataIndex: 'urls_count',
        key: 'urls_count',
      },
      {
        title: '爬取时间',
        dataIndex: 'spider_time',
        key: 'spider_time',
        render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
      },
    ];
    return (
      <PageHeaderLayout title="收录详情页">
        <Card bordered={false}>
          <div className={styles.title}>Result</div>
          <Table
            style={{ marginBottom: 24 }}
            pagination={false}
            loading={loading}
            dataSource={workresults}
            columns={goodsColumns}
            rowKey="id"
          />
        </Card>
      </PageHeaderLayout>
    );
  }
}
